import type { FieldRule } from 'vant'
// 手机号的校验规则
export const mobileRules: FieldRule[] = [
  {
    required: true,
    message: '请填写手机号',
    trigger: ['onBlur', 'onChange']
  },
  {
    pattern: /^1[3-9]\d{9}$/,
    message: '请填写正确的11位手机号',
    trigger: ['onBlur', 'onChange']
  }
]

// 密码的校验规则
export const passwordRules: FieldRule[] = [
  {
    required: true,
    message: '请填写密码',
    trigger: ['onBlur', 'onChange']
  },
  {
    pattern: /^\w{8,24}$/,
    message: '请填写8-24位字符的密码',
    trigger: ['onBlur', 'onChange']
  }
]

// 验证码的校验规则
export const codedRules: FieldRule[] = [
  {
    required: true,
    message: '请填写验证码',
    trigger: ['onBlur', 'onChange']
  },
  {
    pattern: /^\d{6}$/,
    message: '请填写6位数字的密码',
    trigger: ['onBlur', 'onChange']
  }
]

// 名称校验规则
export const nameRules: FieldRule[] = [
  {
    required: true,
    message: '请填写姓名',
    trigger: ['onBlur']
  },
  {
    pattern: /^(?:[\u4e00-\u9fa5·]{2,16})$/,
    message: '请填写中文姓名',
    trigger: ['onBlur']
  }
]
// 身份证号的校验规则
export const idCardRules: FieldRule[] = [
  {
    required: true,
    message: '请填写身份证号',
    trigger: ['onBlur']
  },
  {
    pattern:
      /^[1-9]\d{5}(?:18|19|20)\d{2}(?:0[1-9]|10|11|12)(?:0[1-9]|[1-2]\d|30|31)\d{3}[\dXx]$/,
    message: '请填写正确的身份证号',
    trigger: ['onBlur']
  }
]
